<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of settings
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Email_template extends MX_Controller {

    //put your code here


    function email_template() {
      parent :: __construct();
        $this->load->model(array('admin_commoncall','admin_settings_model','email_template_model'));
		
		//$this->admin_commoncall->check_admin_login();
		$this->template->set_theme('admin');
		$this->template->set_layout('default');	
    }

//---------------Get All Templates---------------------
    function index() {
        $data['emailtemp'] = $this->email_template_model->get_templates();
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('nav_bar','layouts/nav_bar')
                ->set_partial('side_menu','layouts/side_menu')
                ->build('template/email_template', $data);
    }

//-----------Get a Template By template Id-----------------------
    function get_tempalate() {
        $data['emailtemp'] = $this->email_template_model->get_templates();
        if ($this->input->post('email_tempalte')) {
            $this->form_validation->set_rules('email_tempalte', 'email_tempalte', 'required|xss_clean');
            $templateID = $this->input->post('email_tempalte');
            
            
            
            if ($this->form_validation->run()) {
            	
            	$data['row']['info'] = $this->email_template_model->get_template($templateID);
                
                
                $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                        ->set_partial('nav_bar','layouts/nav_bar')
                         ->set_partial('side_menu','layouts/side_menu')
                        ->build('template/email_template', $data);
            } else {
                $this->session->set_flashdata('message', 'Choose Template type');
                redirect('secure/template/email_template', $data);
            }
        }
    }

//----------------Update Template------------------------------
    function update_template() {
        if ($this->input->post('update_template')) {
            $this->form_validation->set_rules('temp_detail', 'temp_detail', 'required|xss_clean');
            $this->form_validation->set_rules('temp_id', 'template_id', 'required|xss_clean');
            $this->form_validation->set_rules('template_status','template_status','required|xss_clean');
            
            $templateID = trim($this->input->post('temp_id'));
            $template_description = trim($this->input->post('temp_detail'));
            $template_status = trim($this->input->post('template_status'));
            
           
            
            if ($this->form_validation->run()) {
                $this->email_template_model->update_template($template_description, $templateID, $template_status);
                $this->session->set_flashdata('message', 'Template Updated Sucessfully');
                redirect('secure/template/email_template');
            }
        }
        $this->session->set_flashdata('message', 'Please Choose a Template!');
        redirect('secure/template/email_template/');
    }

}

?>